<template>
  <div class="app-container">
    <div class="hor mg-b-10">
      <div class="match-width">
        <table class="cus-table match-width" border="1px">
          <div class="loading-overlay">
            <div class="loading-text">加载中...</div>
          </div>
          <tr>
            <th style="">项目名称</th>
            <td>{{ this.projectInfo.name }}</td>
            <th style="">省市</th>
            <td>{{ this.projectInfo.province + "-" + this.projectInfo.city }}</td>
            <th style="">基本信息</th>
            <td>{{ this.projectInfo.yeTaiStr }}</td>
            <th style="">创建时间</th>
            <td>{{ this.projectInfo.createTime }}</td>
            <th style="background-color: #68a4e7; color: #ffffff;">
              <el-link icon="el-icon-upload2" size="mini" class="font-color-white" style="color: #ffffff;"
                       loading="onSaveLoading" v-has-permission="['上传内线标底']"
                       @click="importInnerBidBasebd">去上传标底
              </el-link>
              <el-link type="" icon="el-icon-download" size="mini" class=" font-color-white" v-has-permission="['下载内线标底']"
                       @click="exportInnerBd1()">下载标底
              </el-link>
            </th>
            <th style="background-color: #68a4e7; color: #ffffff;width: 110px;">
              <el-link type="" icon="el-icon-upload2" size="mini" class="font-color-white" style="color: #ffffff;"
                       loading="onSaveLoading" v-has-permission="['上传内线实施标底']"
                       @click="importInnerBidBaseSsbd">去上传实施标底
              </el-link>
              <el-link type="" icon="el-icon-download" size="mini" class=" font-color-white" v-has-permission="['下载内线实施标底']"
                       @click="exportInnerBd2">下载实施标底
              </el-link>
            </th>
            <th style="background-color: #68a4e7; color: #ffffff;width: 100px;">
              <el-link type="" icon="el-icon-plus" size="mini" class=" font-color-white" v-has-permission="['高低压-内线添加、删除项目供应商']"
                       @click="openSupplier()">添加供应商
              </el-link>
            </th>
          </tr>

          <tr>
            <th style="">标底</th>
            <th style="">供应商</th>
            <th style="">供应商状态</th>
            <th style="">第一轮回标</th>
            <th style="">第二轮回标</th>
            <th style="">第三轮回标</th>
            <th style="">第四轮回标</th>
            <th style="">定标</th>
            <th style="">实施标底</th>
            <th style="">实施定标</th>
            <th style="">操作</th>
          </tr>
          <template v-for="(item, index) in supplierData">
            <tr :key="index">
              <td v-if="index === 0" :rowspan="supplierData.length">
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerBidBaseTabulation1"
                         @click="openBidBaseBd(item.innerBidBaseTabulation1)">
                  综合合价: {{
                    item.innerBidBaseTabulation1 != null ? item.innerBidBaseTabulation1.totalPriceCount.toFixed(2) : null
                  }}
                </el-link>
              </td>
              <td>{{ item.supplyCompany != null ? item.supplyCompany.name : null }}</td>
              <td>{{ item.bidStatusName }} ( {{ item.weedOutJieDuan }})</td>
              <td>
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerTabulation1"
                         @click="openT1(item.innerTabulation1)">
                  综合合价:{{ item.innerTabulation1 != null ? item.innerTabulation1.totalPriceCount.toFixed(2) : null }}
                </el-link>
              </td>
              <td>
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerTabulation2"
                         @click="openT2(item.innerTabulation2)">
                  综合合价:{{ item.innerTabulation2 != null ? item.innerTabulation2.totalPriceCount.toFixed(2) : null }}
                </el-link>
              </td>
              <td>
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerTabulation3"
                         @click="openT3(item.innerTabulation3)">
                  综合合价:{{ item.innerTabulation3 != null ? item.innerTabulation3.totalPriceCount.toFixed(2) : null }}
                </el-link>
              </td>
              <td>
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerTabulation4"
                         @click="openT4(item.innerTabulation4)">
                  综合合价:{{ item.innerTabulation4 != null ? item.innerTabulation4.totalPriceCount.toFixed(2) : null }}
                </el-link>
              </td>
              <td>
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerTabulation5"
                         @click="openT5(item.innerTabulation5)">
                  综合合价:{{ item.innerTabulation5 != null ? item.innerTabulation5.totalPriceCount.toFixed(2) : null }}
                </el-link>
              </td>
              <td v-if="index === 0" :rowspan="supplierData.length">
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerBidBaseTabulation2"
                         @click="openBidBaseSsbd(item.innerBidBaseTabulation2)">
                  综合合价:{{
                    item.innerBidBaseTabulation2 != null ? item.innerBidBaseTabulation2.totalPriceCount.toFixed(2) : null
                  }}
                </el-link>
              </td>
              <td>
                <el-link type="primary" icon="" size="mini"
                         v-if="item.innerTabulation6"
                         @click="openT6(item.innerTabulation6)">
                  综合合价:{{ item.innerTabulation6 != null ? item.innerTabulation6.totalPriceCount.toFixed(2) : null }}
                </el-link>
              </td>
              <td v-if="item != null">
                <div>
                  <el-link type="primary" size="mini" class=" " v-has-permission="['高低压-内线上传供应商清单']"
                           @click="uploadInnerTabulation(item)">上传清单
                  </el-link>
                </div>
                <div>
                  <el-link type="warning" size="mini" class=" " v-has-permission="['高低压-内线供应商设置状态']"
                           @click="openSupplierStatus(item)">设置状态
                  </el-link>
                </div>
                <div>
                  <el-link type="success" size="mini" class=" " v-has-permission="['高低压-内线供应商清单管理']"
                           @click="openTabulation(item)">清单管理
                  </el-link>
                </div>
                <div>
                  <el-link type="danger" size="mini" class=" " v-has-permission="['高低压-内线添加、删除项目供应商']"
                           @click="deleteBiddingCompany(item)">删除供应商
                  </el-link>
                </div>
              </td>
            </tr>
          </template>

        </table>
      </div>
    </div>
    <div class="">
      <el-dialog
        title="添加供应商"
        :visible.sync="toDialogVisible"
        width="65%"
        :before-close="handleClose"
        :close-on-click-modal="false">
        <!--筛选功能-->
        <div class="hor mg-b-10 ver-center flex1">
          <el-cascader
            v-model="filterCompany"
            placeholder="请选择省市"
            :options="areaData"
            @change="onCompanyFilterChange"
            :props="{ expandTrigger: 'hover',label:'label',value:'value',checkStrictly:true}"
            filterable show-all-levels
            clearable></el-cascader>
          <div class="hor pd-l-10">
            <el-input class="" v-model="supplyCompanyName" placeholder="请输入供应商名" clearable></el-input>
          </div>
          <div class="pd-l-10"></div>
          <el-button type="primary" icon="el-icon-search" @click="onClickSearch()" class="">筛选
          </el-button>
        </div>
        <!--  保存选中供应商    -->
        <div>
          <el-table
            ref="table"
            v-loading="listLoading"
            :data="allList"
            :height="autoHeight"
            element-loading-text="Loading"
            @cell-click="onCellClick"
            @selection-change="handleSelectionChange"
            @row-click="onItemClick"
            @row-dblclick="onItemDoubleClick"
            border
            fit
            highlight-current-row
          >
            <el-table-column
              type="selection"
              width="55">
            </el-table-column>
            <el-table-column label="地区" align="center" width="">
              <template slot-scope="scope">
                {{ scope.row.province != null ? scope.row.province : "" }}/
                {{ scope.row.city != null ? scope.row.city : "" }}
              </template>
            </el-table-column>
            <el-table-column label="单位名称" align="center" width="">
              <template slot-scope="scope">
                {{ scope.row.name }}
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="">
              <template slot-scope="scope">
                {{ scope.row.remarks }}
              </template>
            </el-table-column>
            <el-table-column label="创建时间" width="300" align="center">
              <template slot-scope="scope">
                {{ scope.row.createTime }}
              </template>
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer  hor hor-center">
            <el-button type="primary" :loading="onSaveLoading"
                       @click="batchSaveSupplier">添加</el-button>
        </span>
        <div class="hor">
          <div class="flex1"></div>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10,20, 50, 100, 200]"
            :page-size="size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            class="mg-t-10">
          </el-pagination>
        </div>
      </el-dialog>
    </div>
    <div class="">
      <el-dialog
        title="状态设置"
        :visible.sync="supplierStatusDialog"
        :close-on-click-modal=false
        width="700px"
        @open="onDialogOpen"
        center>
        <div class="ver match-width">
          <div class="ver" style="width: 600px;">
            <div class="hor ver-center ver-center mg-t-20">
              <div style="width: 120px;" class="font14 font-text-color-main-title">单位名称</div>
              <el-input class="flex1 font-text-color-main-title" style="width: 50px" :disabled="true"
                        v-model="biddingCompany.supplyCompany.name">
              </el-input>
            </div>
            <div class="hor ver-center ver-center mg-t-20">
              <div class="hor ver-center flex1">
                <div style="width: 120px;" class="font14 font-text-color-main-title">弃标、淘汰阶段</div>
                <el-select class="flex1 font-text-color-main-title" v-model="biddingCompany.weedOutJieDuan"
                           style="width: 225px" clearable placeholder="弃标或淘汰的阶段">
                  <el-option
                    label="回标1"
                    value="回标1">
                  </el-option>
                  <el-option
                    label="回标2"
                    value="回标2">
                  </el-option>
                  <el-option
                    label="回标3"
                    value="回标3">
                  </el-option>
                  <el-option
                    label="回标4"
                    value="回标4">
                  </el-option>
                  <el-option
                    label="定标"
                    value="定标">
                  </el-option>
                  <el-option
                    label="实施定标"
                    value="实施定标">
                  </el-option>
                </el-select>
              </div>
            </div>
            <div class="hor ver-center ver-center mg-t-20">
              <div class="hor ver-center flex1">
                <div style="width: 120px;" class="font14 font-text-color-main-title">状态设置</div>
                <el-select class="flex1 font-text-color-main-title" v-model="biddingCompany.bidStatus"
                           style="width: 225px" clearable placeholder="请选择单位">
                  <el-option
                    label="正常"
                    :value="1">
                  </el-option>
                  <el-option
                    label="弃标"
                    :value="2">
                  </el-option>
                  <el-option
                    label="淘汰"
                    :value="3">
                  </el-option>
                </el-select>
              </div>
            </div>
            <div class="hor ver-center ver-center mg-t-20">
              <div class="hor ver-center flex1">
                <div style="width: 120px;" class="font14 font-text-color-main-title">备注
                </div>
                <el-input class="flex1 font-text-color-main-title" type="textarea" maxlength="512"
                          :autosize="{minRows: 3, }"
                          v-model="biddingCompany.remarks" placeholder="请输入"/>
              </div>
            </div>
          </div>
          <div class="hor match-width ver-center hor-center mg-t-20">
            <el-button @click="supplierStatusDialog = false">取 消</el-button>
            <el-button type="primary" slot="reference" :loading="onSaveLoading" class="mg-l-10"
                       @click="editSupplierStatus">保存
            </el-button>
          </div>
        </div>
      </el-dialog>
    </div>
    <div class="">
      <el-dialog
        title="内线清单管理"
        :visible.sync="tabulationDialog"
        :close-on-click-modal=false
        style="width: 100%"
        center>
        <div class="pd-b5">标底清单</div>
        <div class="match-width">
          <el-table
            ref="table1"
            style="width: 100%"
            v-loading="listLoading"
            :data="innerBidBaseTabulationList"
            element-loading-text="Loading"
            :max-height="autoHeight"
            border
            fit
            highlight-current-row
          >
            <el-table-column label="文件类型" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.jieDuan == 1">
                  {{ "标底" }}
                </div>
                <div v-if="scope.row.jieDuan == 7">
                  {{ "实施标底" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="上传时间" align="center">
              <template slot-scope="scope">
                {{ formatDate(scope.row.createTime) }}
              </template>
            </el-table-column>
            <el-table-column label="文件名称" align="center">
              <template slot-scope="scope">
                {{ scope.row.fileName }}
              </template>
            </el-table-column>
            <el-table-column label="负荷（KVA）" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.loadDf" placeholder="请输入" type="number"
                          @change="onInputChangeInnerSummary(scope.row)">
                  <template slot="append">KVA</template>
                </el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="140">
              <template slot-scope="scope">
                <div class="hor ver-center">
                  <el-button type="primary" class="" size="mini"
                             @click.stop="exportInnerBidBaseTabulation(scope.row)">下载
                  </el-button>
                  <el-button type="danger" size="mini" :loading="onDeleteLoading"
                             @click.stop="deletesByProjectToType(scope.row)">删除
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pd-tb10"></div>
        <div class="pd-b5">供应商内线清单</div>
        <div class="match-width">
          <el-table
            ref="table2"
            style="width: 100%"
            v-loading="listLoading"
            :data="innerTabulationList"
            element-loading-text="Loading"
            :max-height="autoHeight"
            border
            fit
            highlight-current-row
          >
            <el-table-column label="文件类型" align="center">
              <template slot-scope="scope">
                {{ getJieDuanName(scope.row.jieDuan) }}
              </template>
            </el-table-column>
            <el-table-column label="上传时间" align="center">
              <template slot-scope="scope">
                {{ formatDate(scope.row.createTime) }}
              </template>
            </el-table-column>
            <el-table-column label="文件名称" align="center">
              <template slot-scope="scope">
                {{ scope.row.fileName }}
              </template>
            </el-table-column>
            <el-table-column label="负荷（KVA）" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.loadDf" placeholder="请输入" type="number"
                          @change="onInputChangeInnerSummary(scope.row)">
                  <template slot="append">KVA</template>
                </el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="140">
              <template slot-scope="scope">
                <div class="hor ver-center">
                  <el-button type="primary" class="" size="mini"
                             @click.stop="exportTabulation(scope.row)">下载
                  </el-button>
                  <el-button type="danger" size="mini" :loading="onDeleteLoading"
                             @click.stop="deletesByBiddingCompanyToType(scope.row)">删除
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>
    </div>
    <!--    上传供应商清单对话框-->
    <el-dialog
      :visible="uploadDialogVisible"
      fullscreen
      center
      width="100%"
      :before-close="uploadDialogClose"
      title="上传供应商内线清单">
      <upload-inner-tabulation :itemInfo="itemInfo"></upload-inner-tabulation>
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="uploadDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!--上传标底、实施标底-->
    <el-dialog
      :visible="uploadBdDialogVisible"
      fullscreen
      center
      width="100%"
      :before-close="uploadBdDialogClose"
      title="上传项目内线标底、实施标底">
      <upload-inner-bd-tabulation :projectInfo="this.projectInfo"
                                  :choiceBidType="choiceBidType"></upload-inner-bd-tabulation>
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadBdDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="uploadBdDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>

<script>
import {getCityData} from "@/js/cityData";
import uploadInnerTabulation from './uploadInnerTabulation.vue';
import uploadInnerBdTabulation from './uploadInnerBdTabulation.vue';

const requestInnerBidBaseTabulation = require('@/api/tabulation/innerBidBaseTabulation')
const requestInnerTabulation = require('@/api/tabulation/innerTabulation')
const requestSupplier = require('@/api/project/supplyCompany')
const request = require('@/api/project/biddingCompany')
const requestInnerSummary = require('@/api/tabulation/innerSummary')

export default {
  components: {
    uploadInnerTabulation,
    uploadInnerBdTabulation
  },
  data() {
    return {
      allList: [],
      supplierData: [],
      page: 1,
      size: 20,
      total: 0,
      autoHeight: 600,//根据屏幕高度自动计算的高度
      //筛选参数
      params: {
        flag: 1,
      },
      listLoading: false,
      onSaveLoading: false,
      toDialogVisible: false,
      selectRowList: [],
      filterCompany: null,
      supplyCompanyName: null,
      areaData: [],

      biddingCompany: {
        id: null,
        project: {},
        supplyCompany: {},
        innerOuterType: 1,
        weedOutJieDuan: null,
        bidStatus: 1,
        remarks: null,
      },
      supplierStatusDialog: false,
      tabulationDialog: false,
      onDeleteLoading: false,
      innerBidBaseTabulationList: [],
      innerTabulationList: [],
      bidType: null,

      importantInfo: {
        supplyCompanyId: null,
        supplyCompanyName: null,
        biddingCompanyId: null,
        jieDuan: null,
        projectId: null,
        projectName: null,
        bidType: null,
        innerOuterType: null,
        type: null
      },
      uploadDialogVisible: false,
      itemInfo: null,
      uploadBdDialogVisible: false,
      choiceBidType: null,
    }
  },
  beforeMount() {
    this.autoHeight = document.body.scrollHeight - 220
    this.projectInfo = JSON.parse(this.$route.query.projectInfo)
  },
  mounted() {
    this.areaData = getCityData()
    this.fetchData()
    //去掉第三级的信息
    for (let i = 0; i < this.areaData.length; i++) {
      if (this.areaData[i].children != null && this.areaData[i].children.length > 0) {
        for (let j = 0; j < this.areaData[i].children.length; j++) {
          this.areaData[i].children[j].children = null
        }
      }
    }
  },
  methods: {
    formatDate(timestamp) {
      const date = new Date(timestamp);
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      const seconds = String(date.getSeconds()).padStart(2, '0');

      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    getJieDuanName(value) {
      switch (value) {
        case 1:
          return "标底";
        case 2:
          return "回标1";
        case 3:
          return "回标2";
        case 4:
          return "回标3";
        case 5:
          return "回标4"
        case 6:
          return "定标"
        case 7:
          return "实施标底"
        case 8:
          return "实施定标"
        default:
          return "";
      }
    },

    openBidBaseBd(innerBidBaseTabulation1) {
      //type: 1标底  2回标定标
      this.importantInfo = {
        supplyCompanyId: null,
        supplyCompanyName: null,
        biddingCompanyId: null,
        jieDuan: 1,
        projectId: innerBidBaseTabulation1.project.id,
        projectName: innerBidBaseTabulation1.project.name,
        bidType: innerBidBaseTabulation1.bidType,
        innerOuterType: 1,
        type: 1
      }
      this.openTabulationDetails()
    },
    openT1(innerTabulation1) {
      this.importantInfo = {
        supplyCompanyId: innerTabulation1.supplyCompany.id,
        supplyCompanyName: innerTabulation1.supplyCompany.name,
        biddingCompanyId: innerTabulation1.biddingCompanyId,
        jieDuan: innerTabulation1.jieDuan,
        projectId: this.projectInfo.id,
        projectName: this.projectInfo.name,
        bidType: null,
        innerOuterType: 1,
        type: 2
      }
      this.openTabulationDetails()
    },
    openT2(innerTabulation2) {
      this.importantInfo = {
        supplyCompanyId: innerTabulation2.supplyCompany.id,
        supplyCompanyName: innerTabulation2.supplyCompany.name,
        biddingCompanyId: innerTabulation2.biddingCompanyId,
        jieDuan: innerTabulation2.jieDuan,
        projectId: this.projectInfo.id,
        projectName: this.projectInfo.name,
        bidType: null,
        innerOuterType: 1,
        type: 2
      }
      this.openTabulationDetails()
    },
    openT3(innerTabulation3) {
      this.importantInfo = {
        supplyCompanyId: innerTabulation3.supplyCompany.id,
        supplyCompanyName: innerTabulation3.supplyCompany.name,
        biddingCompanyId: innerTabulation3.biddingCompanyId,
        jieDuan: innerTabulation3.jieDuan,
        projectId: this.projectInfo.id,
        projectName: this.projectInfo.name,
        bidType: null,
        innerOuterType: 1,
        type: 2
      }
      this.openTabulationDetails()
    },
    openT4(innerTabulation4) {
      this.importantInfo = {
        supplyCompanyId: innerTabulation4.supplyCompany.id,
        supplyCompanyName: innerTabulation4.supplyCompany.name,
        biddingCompanyId: innerTabulation4.biddingCompanyId,
        jieDuan: innerTabulation4.jieDuan,
        projectId: this.projectInfo.id,
        projectName: this.projectInfo.name,
        bidType: null,
        innerOuterType: 1,
        type: 2
      }
      this.openTabulationDetails()
    },
    openT5(innerTabulation5) {
      this.importantInfo = {
        supplyCompanyId: innerTabulation5.supplyCompany.id,
        supplyCompanyName: innerTabulation5.supplyCompany.name,
        biddingCompanyId: innerTabulation5.biddingCompanyId,
        jieDuan: innerTabulation5.jieDuan,
        projectId: this.projectInfo.id,
        projectName: this.projectInfo.name,
        bidType: null,
        innerOuterType: 1,
        type: 2
      }
      this.openTabulationDetails()
    },
    openBidBaseSsbd(innerBidBaseTabulation2) {
      this.importantInfo = {
        supplyCompanyId: null,
        supplyCompanyName: null,
        biddingCompanyId: null,
        jieDuan: 7,
        projectId: innerBidBaseTabulation2.project.id,
        projectName: innerBidBaseTabulation2.project.name,
        bidType: innerBidBaseTabulation2.bidType,
        innerOuterType: 1,
        type: 1
      }
      this.openTabulationDetails()
    },
    openT6(innerTabulation6) {
      this.importantInfo = {
        supplyCompanyId: innerTabulation6.supplyCompany.id,
        supplyCompanyName: innerTabulation6.supplyCompany.name,
        biddingCompanyId: innerTabulation6.biddingCompanyId,
        jieDuan: innerTabulation6.jieDuan,
        projectId: this.projectInfo.id,
        projectName: this.projectInfo.name,
        bidType: null,
        innerOuterType: 1,
        type: 2
      }
      this.openTabulationDetails()
    },

    openTabulationDetails() {
      const {href} = this.$router.resolve({
        path: "/innerDetails/innerTabulationDetails?importantInfo=" + JSON.stringify(this.importantInfo)
      })
      window.open(href, '_blank')//新窗口打开页面会卡死所以不开新窗口
    },

    getSupplierList() {
      this.listLoading = true
      const data = new FormData()
      for (var key in this.params) {//直接去除掉空值的对象
        if (this.isEmpty(this.params[key])) {
          delete this.params[key]
        }
      }
      data.append('params', JSON.stringify(this.params))
      data.append('page', this.page)
      data.append('size', this.size)

      const sortList = []
      sortList.push(
        {
          direction: 'desc',
          property: 'createTime'
        }
      )
      data.append('sortJsonStr', JSON.stringify(sortList))
      requestSupplier.getList(data).then(response => {
        this.allList = response.data
        this.total = response.totalElements

        this.listLoading = false
      })
    },
    openSupplier() {
      this.getSupplierList()
      this.toDialogVisible = true
    },
    handleClose() {
      // this.filterCompany = []
      // this.companyIdList = []
      this.toDialogVisible = false;
      this.fetchData()
    },
    onClickSearch() {//点击搜索
      this.page = 1;
      if (!this.isEmpty(this.searchName)) {
        this.params['name_like'] = ('%' + this.searchName.trim() + '%')
      } else {
        this.params['name_like'] = ''
      }
      if (!this.isEmpty(this.searchType)) {
        this.params['type_like'] = ('%' + this.searchType.trim() + '%')
      } else {
        this.params['type_like'] = ''
      }
      if (!this.isEmpty(this.supplyCompanyName)) {
        this.params['name_like'] = ('%' + this.supplyCompanyName.trim() + '%')
      } else {
        this.params['name_like'] = ''
      }
      this.getSupplierList()
    },
    onCompanyFilterChange(val) {
      if (val) {
        if (val.length == 2) {
          this.params.province = val[0];
          this.params.city = val[1];
        } else if (val.length == 1) {
          this.params.province = val[0];
          this.params.city = "";
        } else {
          this.params.province = "";
          this.params.city = "";
        }
        // this.params.page=1;
        // this.fetchData();
      } else {
        this.params.province = "";
        this.params.city = "";
        // this.fetchData();
      }
      const one = val[0]
      const two = val[1]
      this.onClickSearch()
    },
    onCellClick(row, column, cell, event) {
      if (column.type == 'selection') {
        this.$refs.table.toggleRowSelection(row)
      }
    },
    handleSelectionChange(rowList) {//多选变化监听
      this.selectRowList = rowList
    },
    onItemClick(row) {//单行点击
    },
    onItemDoubleClick(row) {//单行双击
      this.onClickView(row)
    },
    handleSizeChange(val) {
      this.size = val
      this.getSupplierList()
    },
    handleCurrentChange(val) {
      this.page = val
      this.getSupplierList()
    },
    //添加供应商(批量)
    batchSaveSupplier() {
      this.onSaveLoading = true
      let biddingCompanys = []
      if (this.selectRowList.length > 0)
        for (let i = 0; i < this.selectRowList.length; i++) {
          let saveObj = {
            id: null,
            project: this.projectInfo,
            supplyCompany: this.selectRowList[i],
            innerOuterType: 1,
            bidStatus: 1,
            remarks: null,
          }
          biddingCompanys.push(saveObj)
        }
      request.saveByJsonBatch(biddingCompanys).then(response => {
        this.onSaveLoading = false
        this.toDialogVisible = false
        this.$message({
          message: '保存成功',
          type: 'success',
          duration: 2000
        })
        this.fetchData()
      }).catch((e) => {
        this.onSaveLoading = false
      })
    },
    getInnerBidBaseList() {
      this.listLoading = true
      const data = new FormData()
      data.append('flag', 1)
      data.append('projectId', this.projectInfo.id)
      const sortList = []
      sortList.push(
        {
          direction: 'desc',
          property: 'createTime'
        }
      )
      data.append('sortJsonStr', JSON.stringify(sortList))
      requestInnerSummary.getSummaryList(data).then(response => {
        this.innerBidBaseTabulationList = response.data
        this.total = response.totalElements
        this.listLoading = false
      })
    },
    getInnerTabulationList(biddingCompanyId) {
      this.listLoading = true
      const data = new FormData()
      data.append('flag', 1)
      data.append('projectId', this.projectInfo.id)
      if (biddingCompanyId != null && biddingCompanyId != undefined && biddingCompanyId != "") {
        data.append('biddingCompanyId', biddingCompanyId)
      }
      const sortList = []
      sortList.push(
        {
          direction: 'desc',
          property: 'createTime'
        }
      )
      data.append('sortJsonStr', JSON.stringify(sortList))
      requestInnerSummary.getSummaryList(data).then(response => {
        this.innerTabulationList = response.data
        this.total = response.totalElements
        this.listLoading = false
      })
    },
    openTabulation(item) {
      this.getInnerBidBaseList()
      this.getInnerTabulationList(item.id)
      this.tabulationDialog = true
    },
    uploadInnerTabulation(item) {
      this.itemInfo = item; // 将需要传递的数据赋值给data中的item
      this.uploadDialogVisible = true; // 打开对话框
    },
    uploadDialogClose() {
      this.itemInfo = null;
      this.uploadDialogVisible = false;
      this.fetchData()
    },
    openSupplierStatus(item) {
      this.biddingCompany = item
      this.supplierStatusDialog = true
    },
    onDialogOpen() {

    },
    //编辑供应商状态
    editSupplierStatus() {
      this.onSaveLoading = true
      request.saveByJson(this.biddingCompany).then(response => {
        this.onSaveLoading = false
        this.$message({
          message: '保存成功',
          type: 'success',
          duration: 2000
        })
        this.supplierStatusDialog = false
        this.fetchData()
      }).catch((e) => {
        this.onSaveLoading = false
      })
    },

    //编辑清单关联信息
    onInputChangeInnerSummary(row) {
      this.onSaveLoading = true
      //把选择的权限赋值过去
      const data = new FormData()
      data.append('json', JSON.stringify(row));
      requestInnerSummary.saveByJson(data).then(response => {
        this.onSaveLoading = false
        this.$message({
          message: '保存成功',
          type: 'success',
          duration: 2000
        })
      }).catch((e) => {
        this.onSaveLoading = false
      })
    },

    fetchData() {
      this.listLoading = true
      const data = new FormData()
      data.append('projectId', this.projectInfo.id)
      data.append('innerOuterType', 1)

      const sortList = []
      sortList.push(
        {
          direction: 'desc',
          property: 'createTime'
        }
      )
      data.append('sortJsonStr', JSON.stringify(sortList))
      request.getList2(data).then(response => {
        this.supplierData = response.data
        this.total = response.totalElements
        this.listLoading = false
        var loadingOverlay = document.querySelector('.loading-overlay');
        if (loadingOverlay) {
          loadingOverlay.style.display = 'none';
        }
      })
    },
    exportInnerBd1() {
      window.open(process.env.VUE_APP_BASE_API + "/mgt/innerBidBaseTabulation/exportInnerBd?projectId=" + this.projectInfo.id + "&bidType=" + 1)
    },
    exportInnerBd2() {
      window.open(process.env.VUE_APP_BASE_API + "/mgt/innerBidBaseTabulation/exportInnerBd?projectId=" + this.projectInfo.id + "&bidType=" + 2)
    },
    exportInnerBidBaseTabulation(row) {
      let bidType = 0;
      if (row.jieDuan == 1) {
        bidType = 1
      } else if (row.jieDuan == 7) {
        bidType = 2
      }
      window.open(process.env.VUE_APP_BASE_API + "/mgt/innerBidBaseTabulation/exportInnerBd?projectId=" + this.projectInfo.id + "&bidType=" + bidType)
    },
    exportTabulation(row) {
      window.open(process.env.VUE_APP_BASE_API + "/mgt/innerTabulation/exportInnerQd?biddingCompanyId=" + row.biddingCompany.id + "&jieDuan=" + row.jieDuan)
    },

    uploadBdDialogClose() {
      this.choiceBidType = null;
      this.uploadBdDialogVisible = false;
      this.fetchData()
    },
    importInnerBidBasebd() {
      this.choiceBidType = 1;
      this.uploadBdDialogVisible = true;
    },
    importInnerBidBaseSsbd() {
      this.choiceBidType = 2;
      this.uploadBdDialogVisible = true;
    },

    //删除标底
    deletesByProjectToType(row) {
      this.$message({
        message: '操作中',
        type: 'warning',
        duration: 1000
      })
      this.onDeleteLoading = true
      const data = new FormData()
      data.append('projectId', row.project.id)
      data.append('bidType', row.jieDuan)
      requestInnerBidBaseTabulation.deletesByProjectToType(data).then(response => {
        this.$message({
          message: '删除成功',
          type: 'success',
          duration: 3000
        })
        this.onDeleteLoading = false
        this.onDeleteShow = false
        this.getInnerBidBaseList()
        this.fetchData()
      }).catch((e) => {
        this.onDeleteLoading = false
      })
    },
    deletesByBiddingCompanyToType(row) {
      this.$message({
        message: '操作中',
        type: 'warning',
        duration: 1000
      })
      this.onDeleteLoading = true
      const data = new FormData()
      data.append('biddingCompanyId', row.biddingCompany.id)
      data.append('jieDuan', row.jieDuan)
      requestInnerTabulation.deletesByBiddingCompanyToType(data).then(response => {
        this.$message({
          message: '删除成功',
          type: 'success',
          duration: 3000
        })
        this.onDeleteLoading = false
        this.onDeleteShow = false
        this.getInnerTabulationList(row.biddingCompany.id)
        this.fetchData()
      }).catch((e) => {
        this.onDeleteLoading = false
      })
    },
    deleteBiddingCompany(row, index) {
      this.$confirm('删除后不可恢复，是否确定删除', '提示', {
        showCancelButton: true,
        confirmButtonText: "删除"
      })
        .then(_ => {
          this.onSaveLoading = true;
          const data = new FormData()
          data.append('ids', [row.id])
          //删除批次及关联数据
          request.batchDelete(data).then(response => {
            this.onSaveLoading = false;
            this.$message({
              message: "删除成功",
              type: 'success',
              duration: 3000
            })
            this.fetchData()
          })
          this.onSaveLoading = false;
        }).catch(_ => {
        this.onSaveLoading = false;
      });
    }
  }
}
</script>

<style scoped>
.cus-table {
  border-collapse: collapse;
  text-align: center;
}

.cus-table td, .cus-table th {
  border: 1px solid #cad9ea;
  color: #424242;
  height: 50px;
}

.cus-table th {
  background-color: #EFEFEF;
  width: 100px;
  color: #414141;
  font-size: 14px;
}




.cus-table.match-width {
  position: relative;
}
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}
.loading-text {
  font-size: 20px;
  font-weight: bold;
}
</style>
